from odoo import models, api

 
class DocumentsDashboard(models.TransientModel):
    _name = "documents.dashboard"
    _description = "单据仪表板"

    # 通用打开器：通过 xmlid 打开现有 act_window（目标=弹窗）
    def _open(self, xmlid):
        action = self.env.ref(xmlid).sudo().read()[0]
        return action

    @api.model
    def action_open_dashboard(self):
        # 清理当前用户旧记录，避免 Kanban 列出多条
        self.sudo().search([('create_uid', '=', self.env.uid)]).unlink()
        record = self.sudo().create({})
        return {
            'type': 'ir.actions.act_window',
            'name': '单据打印中心',
            'res_model': 'documents.dashboard',
            'view_mode': 'kanban',
            'views': [(self.env.ref('gs_documents.view_documents_dashboard_kanban').id, 'kanban')],
            'target': 'current',
            'domain': [('id', '=', record.id)],
            'context': {},
        }

    # 销售相关
    def action_open_proforma_quotation(self):
        return self._open('gs_documents.action_documents_proforma_quotation_wizard')

    def action_open_proforma_invoice(self):
        return self._open('gs_documents.action_documents_proforma_invoice_wizard')

    def action_open_invoice(self):
        return self._open('gs_documents.action_documents_invoice_wizard')

    # 物流/采购相关
    def action_open_ddt(self):
        return self._open('gs_documents.action_documents_ddt_wizard')

    def action_open_shipping_list(self):
        return self._open('gs_documents.action_documents_shipping_list_wizard')

    def action_open_packing_list(self):
        return self._open('gs_documents.action_documents_packing_list_wizard')

    def action_open_po_summary(self):
        return self._open('gs_documents.action_documents_po_summary_wizard')

    def action_open_back_order(self):
        return self._open('gs_documents.action_documents_back_order_wizard')